//
//  BaseViewController.swift
//  CJPWB
//
//  Created by 陈锦彭 on 16/3/13.
//  Copyright © 2016年 chenjinpeng. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {
    //懒加载访客视图
    lazy var visitorView : VisitorView = VisitorView.visitorView()
    //判断是否登陆属性,决定着进入访客视图还是登陆视图
    var isLogin = UserAccountViewModel.shareInstance.isLogin
    
    // MARK: - 回调函数
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }

}

// MARK: - 加载访客视图
extension BaseViewController {
    
    private func setupVisitorView() {
        //1.创建访客视图
        view = visitorView
        
        //2. 设置两边的按钮
        //访问视图navigationItem的监听
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "leftBarButtonItemClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "rightBarButtonItemClick")
        
        //访问视图中间按钮的监听
        visitorView.registerBtn.addTarget(self, action: "leftBarButtonItemClick", forControlEvents: .TouchUpInside)
        visitorView.LoginBtn.addTarget(self, action: "rightBarButtonItemClick", forControlEvents: .TouchUpInside)
   }

}


// MARK: - 点击事件的处理
extension BaseViewController {
    
    @objc private func leftBarButtonItemClick() {
        print("leftBarButtonItemClick")
  }
    
    @objc private func rightBarButtonItemClick() {
        //创建一个webview
        let OAuthVC = OAuthViewController()
        let navVC = UINavigationController(rootViewController: OAuthVC)
        
        //model出来
        presentViewController(navVC, animated: true, completion: nil)
        
    }
    
}
